//
//  CollectionViewController.m
//  MKUITestApp
//
//  Created by sushangjin on 2020/6/5.
//  Copyright © 2020 sushangjin. All rights reserved.
//

#import "CollectionViewController.h"
#import <MKUI/MKUI.h>
#import "Item.h"
#import "TableViewController.h"
#import "ItemCVCell.h"
@interface CollectionViewController ()
@end

@implementation CollectionViewController
+ (MKTFuncItem *)funcItem{
    return [MKTFuncItem funcWithName:@"CollectionViewController" viewControllerClass:self];
}
- (id)init{
    UICollectionViewFlowLayout *flayout = [[UICollectionViewFlowLayout alloc] init];
    if(self=[super initWithCollectionViewLayout:flayout]){
        self.tabBarItem.title = @"Collection";
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"Collection";
    [self __reloadData];
}
- (void)__reloadData{
    [self.model removeAllSectionModels];
    for (int i=0; i<100; i++) {
        NSString *name = nil;
        if(i%2==0){
            name = [NSString stringWithFormat:@"Table_%@",@(i)];
        }else{
            name = [NSString stringWithFormat:@"Collection_%@",@(i)];
        }
        
        MKUICollectionViewCellModel *cm = [MKUICollectionViewCellModel modelWithValue:[[Item alloc] initWithName:name] cellClass:[ItemCVCell class]];
        
        if(i%2==0){
            cm.whenClick = ^(MKUICollectionViewCellModel *cm) {
                [cm.collectionView.mk_navigationControllerOfFirst pushViewController:[TableViewController new] animated:YES];
            };
        }else{
            cm.whenClick = ^(MKUICollectionViewCellModel *cm) {
                [cm.collectionView.mk_navigationControllerOfFirst pushViewController:[CollectionViewController new] animated:YES];
            };
        }
        [self.model addCellModel:cm];
    }
    [self.model reloadCollectionViewData];
}
@end
